package com.cxh.supermarket.web.controller.labor;

import com.cxh.supermarket.common.annotation.Log;
import com.cxh.supermarket.common.constant.CacheNames;
import com.cxh.supermarket.common.core.controller.BaseController;
import com.cxh.supermarket.common.core.domain.R;
import com.cxh.supermarket.common.enums.BusinessType;
import com.cxh.supermarket.common.enums.OperatorType;
import com.cxh.supermarket.system.domain.SysRegion;
import com.cxh.supermarket.system.domain.vo.AllRegionVo;
import com.cxh.supermarket.system.service.SysRegionService;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * APP行政区划
 *
 * @author shichunjie
 * @since 2024/1/19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/labor/mobile/region")
public class RegionController extends BaseController {

    private final SysRegionService regionService;

    /**
     * 行政区划下拉数据源
     */
    @Log(title = "行政区划查询", businessType = BusinessType.QUERY,operatorType = OperatorType.MOBILE)
    @GetMapping("/list")
    public R<List<SysRegion>> select(@RequestParam(required = false, defaultValue = "100000") String code) {
        List<SysRegion> list = regionService.selectList(code);
        return R.ok(list);
    }

    /**
     * 行政区划根据code查询坐标
     */
    @Log(title = "根据行政code查询坐标", businessType = BusinessType.QUERY,operatorType = OperatorType.MOBILE)
    @GetMapping("/selectCoordinate")
    @Cacheable(value = CacheNames.SYS_REGION_COORDINATE, key = "#code", sync = true)
    public R<SysRegion> selectCoordinate(@RequestParam String code) {
        return R.ok(regionService.selectCoordinate(code));
    }

    /**
     * 查询所有行政区划
     */
    @Log(title = "查询所有行政区划", businessType = BusinessType.QUERY,operatorType = OperatorType.MOBILE)
    @GetMapping("/getAll")
    public R<List<AllRegionVo>> getAll() {
        return R.ok(regionService.getAll());
    }
    /**
     * 查询所有行政区划（没有全山东）
     */
    @Log(title = "查询所有行政区划（没有全山东）", businessType = BusinessType.QUERY,operatorType = OperatorType.MOBILE)
    @GetMapping("/getAllA")
    public R<List<AllRegionVo>> getAllA() {
        return R.ok(regionService.getAllA());
    }
}
